package com.shux.utils.md5;

import java.security.MessageDigest;

import org.apache.shiro.crypto.hash.Md5Hash;
import org.junit.Test;

/**
 * 说明：MD5处理 创建人：Simba.hua 修改时间：2014年9月20日
 * 
 * @version
 */
public class MD5 {

	public static String md5(String str) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(str.getBytes());
			byte b[] = md.digest();

			int i;

			StringBuffer buf = new StringBuffer("");
			for (int offset = 0; offset < b.length; offset++) {
				i = b[offset];
				if (i < 0)
					i += 256;
				if (i < 16)
					buf.append("0");
				buf.append(Integer.toHexString(i));
			}
			str = buf.toString();
		} catch (Exception e) {
			e.printStackTrace();

		}
		return str;
	}

	public static void main(String[] args) {
		System.out.println(md5("31119@qq.com" + "123456"));
		System.out.println(md5("mj1"));
	}
	//@Test
	public void testMd5(){
	    String password = "admin";
	    int hashIterations = 2;//散列次数
	    String target = "21232f297a57a5a743894a0e4a801fc3";
	    Md5Hash md5hash = new Md5Hash(password,null,hashIterations);
	    System.out.println(md5hash.toString());
	    
	}
}
